/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.jrill.persistence;

import java.util.List;
import org.jrill.Participant;
import org.jrill.Workflow;

/**
 * Interface to persist workflow
 * @author K.Waga
 */
public interface PersistenceManager {
    /**
     * Gets workflow by given id.
     * @param id
     * @return
     */
    public Workflow getById(Long id);
    /**
     * Gets workflow by given id and update version.
     * some implementation may through Optimistick Lock Exception.
     * @param id
     * @param version
     * @return
     */
    public Workflow getByIdWithVersion(Long id, Long version);
    /**
     * Finds workflows with current activity held by given owner.
     * @param owner
     * @return
     */
    public List<Workflow> findUnprocessedWorkflowByParticipant(Participant owner);

    /**
     * Finds workflows with current activity held by given owner.
     * @param owner
     * @param firstResult
     * @param maxRow
     * @return
     */
    public List<Workflow> findUnprocessedWorkflowByParticipant(Participant owner, int firstResult, int maxRow);

    /**
     * Finds workflows which contains given participant in activities.
     * @param participant
     * @return
     */
    public List<Workflow> findAllWorkflowByParticipant(Participant participant);

    /**
     * Finds workflows which contains given participant in activities.
     * @param participant
     * @param firstResult
     * @param maxRow
     * @return
     */
    public List<Workflow> findAllWorkflowByParticipant(Participant participant, int firstResult, int maxRow);

    /**
     * Saves given workflow to persistence.
     * @param workflow
     */
    public void save(Workflow workflow);

    /**
     * Removes given workflow from persistence.
     * @param workflow
     */
    public void delete(Workflow workflow);
    
    /**
     * Returns newly genarated Workflow with default activity list lenth. 
     * @return
     */
    Workflow newWorkflow();
    /**
     * Returns newly genarated Workflow with given activity list lenth.
     * @param length size of activity list
     * @return
     */
    Workflow newWorkflow(int length);
}
